/*
 * 
 * Version 1.00
 * 
 * Created on 2007-6-4
 * Encoding GB2312
 */
package net.comm.user.service.impl;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.List;
import java.util.Vector;

import net.comm.page.PageCtr;
import net.comm.param.service.impl.SequenceMgr;
import net.comm.shequ.bean.BaseShequ;
import net.comm.shequ.service.impl.ShequServiceImpl;
import net.comm.shequ.web.form.ShequForm;
import net.comm.util.Ageutil;
import net.comm.util.ChineseCalendar;
import net.comm.util.DatetimeUtil;
import net.comm.check.service.impl.JifenServiceImpl;
import net.comm.common.Decode;
import net.comm.common.Email;
import net.comm.common.GlbFinal;
import net.comm.common.ReturnMessage;
import net.comm.common.common;
import net.comm.encrypt.DesEncrypt;
import net.comm.file.service.impl.FilesServiceImpl;
import net.comm.file.web.form.FilesForm;

import net.comm.user.bean.BaseDetails;
import net.comm.user.bean.BaseUsers;
import net.comm.user.db.DbUserHomeService;
import net.comm.user.db.DbUsersService;
import net.comm.user.db.UserHomeServiceSqlMysql;
import net.comm.user.db.UserSetServiceSqlMysql;
import net.comm.user.db.UsersServiceSqlMysql;
import net.comm.user.web.form.ContactsForm;
import net.comm.user.web.form.DetailsForm;
import net.comm.user.web.form.UserHomeForm;
import net.comm.user.web.form.UsersForm;
import net.comm.user.web.form.UsertempForm;
import net.comm.util.DbcpPool;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.log4j.Logger;
import org.sakaiproject.db.impl.BasicSqlService;


/**
 *
 * @author hcgong(hcgong@sina.com)
 * @version 1.0
 * @date 2007-6-4
 */
public class UsersServiceImpl {

	private static final String Interest = null;
	static Logger logger = Logger.getLogger(UsersServiceImpl.class.getName());

	/**
	 * 
	 * @see net.IUserbasicService.module.other.IUserService
	 * 		#list(net.swift.module.other.ExaQueryBean, net.swift.common.ReturnMessage)
	 */
	public List list(UsersForm theForm,  ReturnMessage msg) 
	{
		List list = null;

		Connection cn = null;
		try
		{
			cn = DbcpPool.getConnection();
			
			UsersServiceSqlMysql servSql = new UsersServiceSqlMysql();
			BasicSqlService  bSqlServ = new BasicSqlService();

			/*
			 * 获得查询SQL语句
			 */
			String sql = servSql.getCountSql1();

			/**
			 * 根据SQL执行结果计算分页相关信息
			 */
			PageCtr page = theForm.getPage();
			page.setTotalNum(bSqlServ.dbCount(cn, sql, null));
			page.caculate();

			//取得FORM中传入的查询参数
			Object[] fields = new Object[3];
			
			fields[0] = theForm.getQryStatus();
			fields[1] = page.getPos()-1;
			fields[2] = page.getPageSize();
			
			sql = servSql.getRecbyPageSql();

			list = bSqlServ.dbRead(cn, sql, fields, new DbUsersService());
			
		    DbcpPool.returnConnection(cn);
		    
		} catch(Exception ex) 
		{
			/**
			 * 记录相关日志
			 */
			logger.error(ex.getMessage());
			try 
			{
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
			} catch(Exception ex1) 
			{
				ex1.printStackTrace();
				logger.error("事务回滚操作失败!ExaServiceImpl->add(01)" , ex1);
			}			
			
		} finally {
			DbcpPool.returnConnection(cn);
		}		
		
		return list;
	}
	/**
	 * 
	 * @see net.IUserbasicService.module.other.IUserService
	 * 		#list(net.swift.module.other.ExaQueryBean, net.swift.common.ReturnMessage)
	 */
	public List adlist(UsersForm theForm,  ReturnMessage msg) 
	{
		List list = new Vector();

		Connection cn = null;
		Statement stmt=null;
		ResultSet rs=null;
		try
		{
			cn = DbcpPool.getConnection();
			
			UsersServiceSqlMysql servSql = new UsersServiceSqlMysql();
			
			StringBuffer sb = new StringBuffer(" where 1=1");

			String nick = theForm.getNick().trim().replaceAll(GlbFinal.SQLINjection, " ");
			if(!nick.equals("")){
				sb.append(" and Nick like '%");
				sb.append(nick);
				sb.append("%' ");
			}
			String email = theForm.getEmail().trim().replaceAll(GlbFinal.SQLINjection, " ");
			if(!email.equals("")){
				
				sb.append(" and Email='");
				sb.append(email);
				sb.append("' ");
			}
			String qryType = theForm.getQryType().replaceAll(GlbFinal.SQLINjection, " ");
			if(!qryType.equals("")){
				
				sb.append(" and type = '");
				sb.append(qryType);
				sb.append("' ");
			}
			
			if(!theForm.getQryStatus().equals("")){
				
				sb.append(" and Status='");
				sb.append(theForm.getQryStatus());
				sb.append("' ");
			}
			if(!theForm.getQryOnline().equals("")){
				
				sb.append(" and Online='");
				sb.append(theForm.getQryOnline());
				sb.append("' ");
			}
			if(!theForm.getQryBgLTime().equals("")){
				
				sb.append(" and LTime > '");
				sb.append(theForm.getQryBgLTime());
				sb.append("' ");
			}
			if(!theForm.getQryEndLTime().equals("")){
				
				sb.append(" and LTime < '");
				sb.append(theForm.getQryEndLTime());
				sb.append("' ");
			}
			
			if(!theForm.getQryOrderby().equals("")){
				
				sb.append(" Order by ");
				sb.append(theForm.getQryOrderby());
				sb.append(" ");
			}else{

				sb.append(" Order by CTime desc ");	
			}

			//查询记录数
			stmt = cn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
			String sql = servSql.getCountSql1();

			logger.debug(sql+sb.toString());
			rs=stmt.executeQuery(sql+sb.toString());
			int nRows = 0;
			if (rs.next())
	           nRows = rs.getInt("COUNT");
			else
			{
	            rs.close();
	            stmt.close();
	            DbcpPool.returnConnection(cn);
			    return list;
			}
			/**
			 * 根据SQL执行结果计算分页相关信息
			 */
			PageCtr page = theForm.getPage();
			page.setTotalNum(nRows);
			page.caculate();

			sb.append(" limit ");
			sb.append(page.getPos()-1);
			sb.append(", ");
			sb.append(page.getPageSize());
			
			 //取记录
			 //sql = servSql.getinterestByUserIDSql();
			sql = servSql.getRecSql();
			 logger.debug(sql+sb.toString());
			 DbUsersService dbuser = new DbUsersService();
			 
			 rs=stmt.executeQuery(sql+sb.toString());
			 while (rs.next())
			 {
				try
				{
					Object obj = dbuser.readSqlResultRecord(rs);
					if (obj != null) list.add(obj);
				}
				catch (Throwable t)
				{
					logger.error(t.getMessage());
				}		
			 }
			 rs.close();
			 stmt.close();
		     DbcpPool.returnConnection(cn);

		} catch(Exception ex) 
		{
			/**
			 * 记录相关日志
			 */
			logger.error(ex.getMessage());
			try {
				if (rs != null)
					rs.close();
				if (stmt != null)
					stmt.close();
				DbcpPool.returnConnection(cn);
			} catch (Exception ex1) {
				ex1.printStackTrace();
			}			
	    }finally {
			try {
				if (rs != null)
					rs.close();
				if (stmt != null)
					stmt.close();
			} catch (Exception ex) {
				ex.printStackTrace();
			}			
			DbcpPool.returnConnection(cn);
		}		
		return list;
	}	
	/**
	 * 
	 * @see net.IUserbasicService.module.other.IUserService
	 * 		#list(net.swift.module.other.ExaQueryBean, net.swift.common.ReturnMessage)
	 */
	public List listbynick(UsersForm theForm,  ReturnMessage msg) 
	{
		List list = null;

		Connection cn = null;
		try
		{
			cn = DbcpPool.getConnection();
			
			UsersServiceSqlMysql servSql = new UsersServiceSqlMysql();
			BasicSqlService  bSqlServ = new BasicSqlService();

			//取得FORM中传入的查询参数
			Object[] fields = new Object[1];
			
			fields[0] = "%"+theForm.getNick()+"%";
			
			String sql = servSql.getRecbyNickSql();

			list = bSqlServ.dbRead(cn, sql, fields, new DbUsersService());
			
		    DbcpPool.returnConnection(cn);
		    
		} catch(Exception ex) 
		{
			/**
			 * 记录相关日志
			 */
			logger.error(ex.getMessage());
			try 
			{
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
			} catch(Exception ex1) 
			{
				ex1.printStackTrace();
				logger.error("事务回滚操作失败!ExaServiceImpl->add(01)" , ex1);
			}			
			
		} finally {
			DbcpPool.returnConnection(cn);
		}		
		
		return list;
	}
	/**
	 * 
	 */
	public List list(String  userID) 
	{
		List list = null;
		Connection cn = null;

		try
		{
			cn = DbcpPool.getConnection();
			
			//取得FORM中传入的查询参数
			Object[] fields = new Object[1];
			
			fields[0] = userID;			

			UsersServiceSqlMysql servSql = new UsersServiceSqlMysql();
						
			BasicSqlService  bSqlServ = new BasicSqlService();

			/*
			 * 获得查询SQL语句
			 */
			String sql = servSql.getByUserIDSql();
									
			list = bSqlServ.dbRead(cn, sql, fields, new DbUsersService());
									
		    DbcpPool.returnConnection(cn);
		    
		} catch(Exception ex) 
		{
			/**
			 * 记录相关日志
			 */
			logger.error(ex.getMessage());
			try 
			{
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
			} catch(Exception ex1) 
			{
				ex1.printStackTrace();
				logger.error("事务回滚操作失败!ExaServiceImpl->add(01)" , ex1);
			}				
			
		} finally {
			DbcpPool.returnConnection(cn);
		}
		
		return list;
	}
	
	/**
	 * @see net.IUserbasicService.module.other.IUserService
	 * 		#get(net.swift.db.tab_paramnostro, net.swift.common.ReturnMessage)
	 */
	public void get(UsersForm theForm, ReturnMessage msg) 
	{

		Connection cn = null;
		try
		{
			cn = DbcpPool.getConnection();
			
			UsersServiceSqlMysql servSql = new UsersServiceSqlMysql();
			BasicSqlService  bSqlServ = new BasicSqlService();
			//取得FORM中传入的查询参数
			Object[] fields = new Object[1];
			
			fields[0] = theForm.getUserID();
			
			String sql = servSql.getbykeySql();
						
			List list = bSqlServ.dbRead(cn, sql, fields, new DbUsersService());
			if(list.size() == 0){
				common.setAppFailMsg(msg , " 会员不存在！");
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
				return;				
			}
			BaseUsers base = (BaseUsers)list.get(0);
			
			BeanUtils.copyProperties(theForm, base);
			
			DbcpPool.closeTran(cn);			
			DbcpPool.returnConnection(cn);
			
		} catch(Exception ex) 
		{
			logger.error("System error , param get about invite" + ex);
			common.setAppFailMsg(msg , ex.getMessage());
			try 
			{
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
			} catch(Exception ex1) 
			{
				ex1.printStackTrace();
				logger.error("事务回滚操作失败!ExaServiceImpl->add(01)" , ex1);
			}				
		} finally {
			DbcpPool.returnConnection(cn);
		}
		
		return ;
	}


	/**
	 * @see net.IUserbasicService.module.other.IUserService
	 * 		#get(net.swift.db.tab_paramnostro, net.swift.common.ReturnMessage)
	 */
	public void sendpwd(UsersForm theForm, ReturnMessage msg) 
	{

		Connection cn = null;
		try
		{
			cn = DbcpPool.getConnection();
			
			//取得FORM中传入的查询参数
			Object[] fields = new Object[1];
			
			fields[0] = theForm.getEmail();
						
			UsersServiceSqlMysql servSql = new UsersServiceSqlMysql();
			
			String sql = servSql.getByEmailSql();
			
			BasicSqlService  bSqlServ = new BasicSqlService();
						
			List list = bSqlServ.dbRead(cn, sql, fields, new DbUsersService());
			
			if(list.size() == 0){
				common.setAppFailMsg(msg , " 取记录失败，请确认邮箱是否正确！");
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
				return;				
			}
			BaseUsers base = (BaseUsers)list.get(0);
			
   		   	//对输入密码解密处理
			String strTemp = Decode.Decode(base.getPassword());
			StringBuffer sb = new StringBuffer("");

			sb.delete(0, sb.length());
			sb.append("尊敬的");
			sb.append(base.getNick());
			sb.append(" ");
			sb.append(":");
			sb.append("<p>&nbsp;&nbsp;您的登录密码:</p>");
			sb.append(strTemp.trim());
			sb.append("　　　　　　　　<br><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;致</p><p>&nbsp;礼！</p>" +
					"<p>&nbsp;&nbsp;&nbsp;&nbsp;</p>");
			
		    Email themail = new Email(GlbFinal.EMAIL_SMTP);  
		    
		    themail.setNeedAuth(true);  
		    themail.setSubject("密码取回");  
		    themail.setBody(sb.toString());  
		    themail.setTo(base.getEmail());  							//"收件人地址"
		    themail.setFrom(GlbFinal.EMAIL_ADDR,GlbFinal.EMAIL_FRNAME);	//发件人

		    themail.setNamePass(GlbFinal.EMAIL_FRUSER, GlbFinal.EMAIL_FRUSERPSD);  	//"用户名","密码"
            themail.sendout();  
			
			DbcpPool.closeTran(cn);			
			DbcpPool.returnConnection(cn);
			
		} catch(Exception ex) 
		{
			logger.error("System error , param get about invite" + ex);
			common.setAppFailMsg(msg , ex.getMessage());
			try 
			{
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
			} catch(Exception ex1) 
			{
				ex1.printStackTrace();
				logger.error("事务回滚操作失败!ExaServiceImpl->add(01)" , ex1);
			}				
		} finally {
			DbcpPool.returnConnection(cn);
		}
		
		return ;
	}
	
	/**
	 *会员注册
	 * @see net.IUserbasicService.module.other.IUserService#add(net.swift.common.ReturnMessage)
	 */
	public String  register(UsersForm theForm, ReturnMessage msg) 
	{
		Connection cn = null;
		String acturl = "";
		try
		{
			cn = DbcpPool.getConnection();
			
			DbcpPool.beginTran(cn);

			UsersServiceSqlMysql servSql = new UsersServiceSqlMysql();
			BasicSqlService  bSqlServ = new BasicSqlService();

			//判断社区资料是否输入
			if(theForm.getVillageID() == 0 && theForm.getVillage().equals("")){
				
				common.setAppFailMsg(msg , "请选择所在的社区！");
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
				return acturl;
			}
			
			//判断邮箱是否已经使用
			Object[] fields2 = new Object[1];
			fields2[0] = theForm.getEmail();

			String sql = servSql.getByEmailSql();
			
			List list = bSqlServ.dbRead(cn, sql, fields2, new DbUsersService());
			if(list.size() > 0){
				common.setAppFailMsg(msg , " Email已经注册，如果忘记密码，请使用取回密码功能！");
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
				return acturl;
			}
			
			//判断用户名是否已经存在
			fields2[0] = theForm.getNick();

			sql = servSql.getByNickSql();
			
			list = bSqlServ.dbRead(cn, sql, fields2, new DbUsersService());
			if(list.size() > 0){
				common.setAppFailMsg(msg , " 用户名已经被使用，请换一个！");
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
				return acturl;
			}
			
			
			
			//插入记录
			Object[] fields = new Object[12];
			
			theForm.setUserID(SequenceMgr.generateSeq(GlbFinal.SEQ_INITDATE,GlbFinal.SEQ_USERID));
			
			fields[0] = theForm.getUserID();
			fields[1] = theForm.getNick();
			fields[2] = theForm.getEmail();
			fields[3] = Decode.Encode(theForm.getPassword());
			fields[4] = GlbFinal.USERSTS_EMAIL;
			fields[5] = theForm.getType();
			fields[6] = DatetimeUtil.getDatetime();
			fields[7] = theForm.getLoginCnt();
			fields[8] = theForm.getLtime();
			fields[9] = theForm.getOnline();
			fields[10] = DatetimeUtil.getDatetime();
			fields[11] = theForm.getRemark();
						
			sql = servSql.getInsertSql();
						
			boolean  res = bSqlServ.dbWrite(cn, sql, fields);
			if(!res){
				common.setAppFailMsg(msg , " 插入记录失败，请检查！");
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
				return acturl;
			}
			
			//保存注册信息到用户临时表中
			UsertempServiceImpl tmpservice = new UsertempServiceImpl();
			UsertempForm tempform = new UsertempForm();
			
			BeanUtils.copyProperties(tempform, theForm);
			
			tmpservice.add(cn, tempform, msg);
			if(msg.getErrCode() != 0){
				return acturl;
			}
			
			/*
			 * 发送验证邮件
			 */
			acturl = sendEmail(theForm, msg); 
			
			DbcpPool.commitTran(cn);
			DbcpPool.closeTran(cn);			
			DbcpPool.returnConnection(cn);
			
		} catch(Exception ex) 
		{
			logger.error("System error , param get about users" + ex);
			common.setAppFailMsg(msg , ex.getMessage());
			try 
			{
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
			} catch(Exception ex1) 
			{
				ex1.printStackTrace();
				logger.error("事务回滚操作失败!ExaServiceImpl->add(01)" , ex1);
			}				
		} finally {
			DbcpPool.returnConnection(cn);
		}
		
		return acturl;
	}
//	/**
//	 *会员注册
//	 * @see net.IUserbasicService.module.other.IUserService#add(net.swift.common.ReturnMessage)
//	 */
//	public String  registerold(UsersForm theForm, ReturnMessage msg) 
//	{
//		Connection cn = null;
//		String acturl = "";
//		try
//		{
//			cn = DbcpPool.getConnection();
//			
//			DbcpPool.beginTran(cn);
//
//			UsersServiceSqlMysql servSql = new UsersServiceSqlMysql();
//			BasicSqlService  bSqlServ = new BasicSqlService();
//
//			//判断邮箱是否已经使用
//			Object[] fields2 = new Object[1];
//			fields2[0] = theForm.getEmail();
//
//			String sql = servSql.getByEmailSql();
//			
//			List list = bSqlServ.dbRead(cn, sql, fields2, new DbUsersService());
//			if(list.size() > 0){
//				common.setAppFailMsg(msg , " Email已经注册，如果忘记密码，请使用取回密码功能！");
//				DbcpPool.rollBackTran(cn);
//				DbcpPool.closeTran(cn);
//				DbcpPool.returnConnection(cn);
//				return acturl;
//			}
//			
//			//判断用户名是否已经存在
//			fields2[0] = theForm.getNick();
//
//			sql = servSql.getByNickSql();
//			
//			list = bSqlServ.dbRead(cn, sql, fields2, new DbUsersService());
//			if(list.size() > 0){
//				common.setAppFailMsg(msg , " 用户名已经被使用，请换一个！");
//				DbcpPool.rollBackTran(cn);
//				DbcpPool.closeTran(cn);
//				DbcpPool.returnConnection(cn);
//				return acturl;
//			}
//			
//			//插入记录
//			Object[] fields = new Object[12];
//			
//			theForm.setUserID(SequenceMgr.generateSeq(GlbFinal.SEQ_INITDATE,GlbFinal.SEQ_USERID));
//			
//			fields[0] = theForm.getUserID();
//			fields[1] = theForm.getNick();
//			fields[2] = theForm.getEmail();
//			fields[3] = Decode.Encode(theForm.getPassword());
//			fields[4] = GlbFinal.USERSTS_EMAIL;
//			fields[5] = theForm.getType();
//			fields[6] = DatetimeUtil.getDatetime();
//			fields[7] = theForm.getLoginCnt();
//			fields[8] = theForm.getLtime();
//			fields[9] = theForm.getOnline();
//			fields[10] = DatetimeUtil.getDatetime();
//			fields[11] = theForm.getRemark();
//						
//			sql = servSql.getInsertSql();
//						
//			boolean  res = bSqlServ.dbWrite(cn, sql, fields);
//			if(!res){
//				common.setAppFailMsg(msg , " 插入记录失败，请检查！");
//				DbcpPool.rollBackTran(cn);
//				DbcpPool.closeTran(cn);
//				DbcpPool.returnConnection(cn);
//				return acturl;
//			}
//			
//			//登记详细资料表
//			DetailsServiceImpl detailservice = new DetailsServiceImpl();
//			DetailsForm detailform = new DetailsForm();
//			
//			detailform.setUserID(theForm.getUserID());
//			detailform.setName(theForm.getName());
//			detailform.setNick(theForm.getNick());
//			detailform.setIntroduction(theForm.getIntroduction());	
//			detailform.setSex(theForm.getSex());
//			detailform.setWork(theForm.getWork());
//			detailform.setWorkSet(theForm.getWorkSet());
//			detailform.setSkill(theForm.getSkill());
//			detailform.setSkillSet(theForm.getSkillSet());
//			detailform.setBirthday(theForm.getBirthday());
//			detailform.setBirthdaySet(theForm.getBirthdaySet());
//			detailform.setStar(theForm.getStar());
//			detailform.setChzodiac(theForm.getChzodiac());
//			
//			detailform.setHome_location(theForm.getHome_location());
//			detailform.setHome_sublocation(theForm.getHome_sublocation());
//			detailform.setHome_area(theForm.getHome_area());
//			detailform.setHome_Set(theForm.getHome_Set());
//			detailform.setCerttype(theForm.getCerttype());
//			detailform.setCertno(theForm.getCertno());
//			detailform.setCertSet(theForm.getCertSet());
//			detailform.setIsArmy(theForm.getIsArmy());
//			detailform.setArmy(theForm.getArmy());
//			detailform.setArmySet(theForm.getArmySet());
//			detailform.setEducation(theForm.getEducation());
//			detailform.setHighSchool(theForm.getHighSchool());
//			detailform.setHsFinshDate(theForm.getHsFinshDate());
//			detailform.setCollege(theForm.getCollege());
//			detailform.setColFinshDate(theForm.getColFinshDate());
//			detailform.setSchoolSet(theForm.getSchoolSet());
//			detailform.setInterest(theForm.getInterest());
//			detailform.setInterestSet(theForm.getInterestSet());
//			
//			//上传个人照片
//			if(theForm.getPicIDPath() != null&&!theForm.getPicIDPath().getFileName().equals("")){
//				
//				FilesForm fileForm = new FilesForm();
//				fileForm.setFormFile(theForm.getPicIDPath());
//				fileForm.setF_info(theForm.getName());
//				fileForm.setF_Zip(GlbFinal.ZIP_135_110);
//				
//				FilesServiceImpl fileservice = new FilesServiceImpl();
//				
//				fileservice.add(cn, fileForm, msg);
//				if(msg.getErrCode() != 0){
//					return acturl;
//				}
//				detailform.setPicID(fileForm.getF_ID());
//			}	
//			//根据身份证取出生日期， 计算生肖 和星座
////			if(theForm.getCertno().length() > 15){
////				String birthday = theForm.getCertno().substring(6, 14);
////				
////				detailform.setBirthday(birthday);
////				
////	        	int year = Integer.valueOf(birthday.substring(0,4));
////	        	int month = Integer.valueOf(birthday.substring(4,6));
////	        	int day = Integer.valueOf(birthday.substring(6,8));
////	        	
////	        	String nl = ChineseCalendar.sCalendarSolarToLundar( year,  month,  day);
////	        	if(nl.length() >= 8){
////	        		int nlyear = Integer.valueOf(nl.trim().substring(0, 4));
////	        		detailform.setChzodiac(Ageutil.sxiao(nlyear));				//生肖
////	        	}
////	        	detailform.setStar(Ageutil.star(month, day));
////			}
//			
//			detailservice.add(cn, detailform, msg);
//			if(msg.getErrCode() != GlbFinal.ERRCODE_SUCCESS){
//				return acturl;
//			}
//			
//			ShequServiceImpl shequservice = new ShequServiceImpl();
//			ShequForm shequForm = new ShequForm();
//			//如果是新建社区，则登记社区信息表
//			if(theForm.getVillageID() == 0 && !theForm.getVillage().equals("")){
//	
//				shequForm.setWork_location(theForm.getWork_location());
//				shequForm.setWork_sublocation(theForm.getWork_sublocation());
//				shequForm.setWork_area(theForm.getWork_area());
//				shequForm.setVillage(theForm.getVillage());
//				shequForm.setMapXY(theForm.getMapXY());
//				shequForm.setMemberNum(1);
//				shequForm.setUserID(theForm.getUserID());
//				
//				shequservice.add(cn, shequForm, msg);
//				if(msg.getErrCode()!= 0){
//					return acturl;
//				}
//				theForm.setVillageID(shequForm.getVillageID());
//			}else{//不是新建社区，则更新社区人数
//				shequForm.Clear();
//				shequForm.setMemberNum(1);
//				shequForm.setVillageID(theForm.getVillageID());
//				
//				shequservice.updsts(cn, shequForm, msg);
//				if(msg.getErrCode()!= 0){
//					return acturl;
//				}
//			}
//			
//			if(theForm.getVillageID() == 0){
//				common.setAppFailMsg(msg , " 请选择居住的小区！");
//				DbcpPool.rollBackTran(cn);
//				DbcpPool.closeTran(cn);
//				DbcpPool.returnConnection(cn);
//				return acturl;
//			}
//			
//			//登记居住信息表
//			UserHomeServiceImpl uhomeservice = new UserHomeServiceImpl();
//			UserHomeForm uhomeForm = new UserHomeForm();
//
//			uhomeForm.setUserID(theForm.getUserID());
//			uhomeForm.setWork_location(theForm.getWork_location());
//			uhomeForm.setWork_sublocation(theForm.getWork_sublocation());
//			uhomeForm.setWork_area(theForm.getWork_area());
//			uhomeForm.setVillageID(theForm.getVillageID());
//			uhomeForm.setBuilding(theForm.getBuilding());
//			uhomeForm.setHouseNo(theForm.getHouseNo());
//			uhomeForm.setFangchanNo(theForm.getFangchanNo());
//			uhomeForm.setFcNoSet(theForm.getFcNoSet());
//			uhomeForm.setFcPicIDSts(GlbFinal.CHKFLAG_NO);
//			uhomeForm.setInTime(theForm.getInTime());
//			uhomeForm.setInTimeSet(theForm.getInTimeSet());
//			uhomeForm.setFamSts(theForm.getFamSts());
//			uhomeForm.setFamStsSet(theForm.getFamStsSet());
//			uhomeForm.setLiveSts(theForm.getLiveSts());
//			uhomeForm.setLiveStsSet(theForm.getLiveStsSet());
//			
//			//上传房产照片
//			if(theForm.getFcPicIDPath() != null&&!theForm.getFcPicIDPath().getFileName().equals("")){
//				
//				FilesForm fileForm = new FilesForm();
//				fileForm.setFormFile(theForm.getFcPicIDPath());
//				fileForm.setF_info(theForm.getName());
//				fileForm.setF_Zip(GlbFinal.ZIP_200_200);
//				
//				FilesServiceImpl fileservice = new FilesServiceImpl();
//				
//				fileservice.add(cn, fileForm, msg);
//				if(msg.getErrCode() != 0){
//					return acturl;
//				}
//				uhomeForm.setFcPicID(fileForm.getF_ID());
//			}	
//			
//			uhomeservice.add(cn, uhomeForm, msg);
//			if(msg.getErrCode()!= 0){
//				return acturl;
//			}
//			//登记会员联系资料表
//			ContactsServiceImpl contactservice = new ContactsServiceImpl();
//			ContactsForm contactForm = new ContactsForm();
//			
//			contactForm.setUserID(theForm.getUserID());
//			contactForm.setEmail(theForm.getEmail());
//			contactForm.setMobile(theForm.getMobile());
//			
//			contactservice.add(cn, contactForm, msg);
//			if(msg.getErrCode()!= 0){
//				return acturl;
//			}
//			
//			/*
//			 * 发送验证邮件
//			 */
//			acturl = sendEmail(theForm, msg); 
//			
//			DbcpPool.commitTran(cn);
//			DbcpPool.closeTran(cn);			
//			DbcpPool.returnConnection(cn);
//			
//		} catch(Exception ex) 
//		{
//			logger.error("System error , param get about users" + ex);
//			common.setAppFailMsg(msg , ex.getMessage());
//			try 
//			{
//				DbcpPool.rollBackTran(cn);
//				DbcpPool.closeTran(cn);
//				DbcpPool.returnConnection(cn);
//			} catch(Exception ex1) 
//			{
//				ex1.printStackTrace();
//				logger.error("事务回滚操作失败!ExaServiceImpl->add(01)" , ex1);
//			}				
//		} finally {
//			DbcpPool.returnConnection(cn);
//		}
//		
//		return acturl;
//	}	
//	/**
//	 * 快速申请通道增加用户，不需验证email 
//	 */
//	public void add(UsersForm theForm, ReturnMessage msg) 
//	{
//
//		Connection cn = null;
//		try
//		{
//			cn = DbcpPool.getConnection();
//			
//			DbcpPool.beginTran(cn);
//
//			UsersServiceSqlMysql servSql = new UsersServiceSqlMysql();
//			BasicSqlService  bSqlServ = new BasicSqlService();
//
//			//判断邮箱是否已经使用
//			Object[] fields2 = new Object[1];
//			fields2[0] = theForm.getEmail();
//
//			String sql = servSql.getByEmailSql();
//			
//			List list = bSqlServ.dbRead(cn, sql, fields2, new DbUsersService());
//			
//			if(list.size() > 0){
//				common.setAppFailMsg(msg , " Email已经注册，如果忘记密码，请使用取回密码功能！");
//				DbcpPool.rollBackTran(cn);
//				DbcpPool.closeTran(cn);
//				DbcpPool.returnConnection(cn);
//				return;
//			}
//
//			//插入记录
//			Object[] fields = new Object[12];
//			
//			theForm.setUserID(SequenceMgr.generateSeq(GlbFinal.SEQ_INITDATE, GlbFinal.SEQ_USERID));
//			
//			fields[0] = theForm.getUserID();
//			fields[1] = theForm.getNick();
//			fields[2] = theForm.getEmail();
//			fields[3] = Decode.Encode(theForm.getPassword());
//			fields[4] = GlbFinal.USERSTS_NORMAL;
//			fields[5] = theForm.getType();
//			fields[6] = DatetimeUtil.getDatetime();
//			fields[7] = theForm.getLoginCnt();
//			fields[8] = theForm.getLtime();
//			fields[9] = theForm.getOnline();
//			fields[10] = DatetimeUtil.getDatetime();
//			fields[11] = theForm.getRemark();
//						
//			sql = servSql.getInsertSql();
//						
//			boolean  res = bSqlServ.dbWrite(cn, sql, fields);
//			if(!res){
//				common.setAppFailMsg(msg , " 插入记录失败，请检查！");
//				DbcpPool.rollBackTran(cn);
//				DbcpPool.closeTran(cn);
//				DbcpPool.returnConnection(cn);
//				return ;
//			}
//			
//			DbcpPool.commitTran(cn);
//			DbcpPool.closeTran(cn);			
//			DbcpPool.returnConnection(cn);
//			
//		} catch(Exception ex) 
//		{
//			logger.error("System error , param get about invite" + ex);
//			common.setAppFailMsg(msg , ex.getMessage());
//			try 
//			{
//				DbcpPool.closeTran(cn);
//				DbcpPool.returnConnection(cn);
//			} catch(Exception ex1) 
//			{
//				ex1.printStackTrace();
//				logger.error("事务回滚操作失败!ExaServiceImpl->add(01)" , ex1);
//			}				
//		} finally {
//			DbcpPool.returnConnection(cn);
//		}
//		
//		return ;
//	}	
	/**
	 *发送激活邮件
	 * @see net.IUserbasicService.module.other.IUserService#add(net.swift.common.ReturnMessage)
	 */
	public String  sendEmail(UsersForm theForm, ReturnMessage msg) 
	{

		DesEncrypt des = new DesEncrypt(); //实例化一个对像 
		
		des.getKey("webmailactive"); //生成密匙 
		
		String strEnc = des.getEncString(String.valueOf(theForm.getUserID())); //加密字符串,返回String的密文 
		
		String  acturl = GlbFinal.WEB_HTTP+GlbFinal.FOLDER_INSTALL +
		"/users.do/active/activeID_" + strEnc + ".html";
		
		//发送邮件到注册邮箱
		Email themail = new Email(GlbFinal.EMAIL_SMTP);  
		StringBuffer emailcont = new StringBuffer("");

		themail.setNeedAuth(true);  
	    themail.setSubject("i友邻社区：欢迎你的加入");  //题目
	    themail.setFrom(GlbFinal.EMAIL_ADDR,GlbFinal.EMAIL_FRNAME);//发件人
	    themail.setNamePass(GlbFinal.EMAIL_FRUSER,GlbFinal.EMAIL_FRUSERPSD);//用户、密码  

	    emailcont.delete(0, emailcont.length());
		emailcont.append("你好:<br>");
		emailcont.append(theForm.getNick());
		emailcont.append(" 欢迎您加入i友邻社区，点击该链接激活:" +
				acturl +
				"&nbsp; <a href='" + acturl +
				"' target='_blank'>激活</a><br><br>");
//		System.out.println("cnt="+ emailcont.toString());
	    themail.setBody(emailcont.toString());  //发送内容
		//调用email类，发送邮件
	    themail.setTo(theForm.getEmail());  //收件人
	    themail.sendout(); 
	    
	    return acturl;
		
	}
	
	
	
	/**
	 * 会员激活
	 * @see net.IUserbasicService.module.other.IUserService#add(net.swift.common.ReturnMessage)
	 */
	public void active(UsersForm theForm, ReturnMessage msg) 
	{

		Connection cn = null;
		try
		{
			cn = DbcpPool.getConnection();
			
			DbcpPool.beginTran(cn);
			
			DesEncrypt des = new DesEncrypt(); //实例化一个对像 
			
			des.getKey("webmailactive"); //生成密匙 
			
			String strEnc = des.getDesString(String.valueOf(theForm.getActiveID())); //解密字符串,返回String的密文 
			
			int userID = Integer.valueOf(strEnc);
			//根据USERID取会员信息 判断状态是否是待激活
			Object[] fields = new Object[1];
			fields[0] = userID;
						
			UsersServiceSqlMysql servSql = new UsersServiceSqlMysql();
			BasicSqlService  bSqlServ = new BasicSqlService();
			String sql = servSql.getbykeySql();
			
			List list = bSqlServ.dbRead(cn, sql, fields, new DbUsersService());
			if(list.size() == 0){
				common.setAppFailMsg(msg , " 会员信息不存在！");
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
				return;				
			}
			BaseUsers base = (BaseUsers)list.get(0);
			
			if(!base.getStatus().equals(GlbFinal.USERSTS_EMAIL)){
				common.setAppFailMsg(msg , " 会员已经激活！");
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
				return;				
			}
			theForm.setEmail(base.getEmail());
			theForm.setNick(base.getNick());
			theForm.setUserID(userID);
			theForm.setType(base.getType());
			
			//修改会员状态为正常
			Object[] fields2 = new Object[12];
			
			fields2[0] = base.getNick();
			fields2[1] = base.getEmail();
			fields2[2] = base.getPassword();
			fields2[3] = GlbFinal.USERSTS_NORMAL;
			fields2[4] = base.getType();
			fields2[5] = base.getCtime();
			fields2[6] = base.getLoginCnt() + 1;
			fields2[7] = DatetimeUtil.getDatetime();
			fields2[8] = base.getOnline();
			fields2[9] = DatetimeUtil.getDatetime();
			fields2[10] = base.getRemark();
			fields2[11] = base.getUserID();
			
			sql = servSql.getUpdateSql();
			boolean  res = bSqlServ.dbWrite(cn, sql, fields2);
			
			if(!res){
				common.setAppFailMsg(msg , " 更新记录失败，请检查！");
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
				return;
			}	
			//取会员注册时的信息
			UsertempServiceImpl tmpservice = new UsertempServiceImpl();
			UsertempForm tempform = new UsertempForm();
			
			tempform.setUserID(theForm.getUserID());
			
			tmpservice.get(cn, tempform, msg);
			if(msg.getErrCode() != 0){
				return;
			}		
			BeanUtils.copyProperties(theForm, tempform);
			
			//删除临时会员表信息
			tmpservice.delete(cn, tempform, msg);
			if(msg.getErrCode() != 0){
				return;
			}			
			
			//登记详细资料表
			DetailsServiceImpl detailservice = new DetailsServiceImpl();
			DetailsForm detailform = new DetailsForm();
			
			BeanUtils.copyProperties(detailform, theForm);
			
			detailservice.add(cn, detailform, msg);
			if(msg.getErrCode() != GlbFinal.ERRCODE_SUCCESS){
				return ;
			}
			
			ShequServiceImpl shequservice = new ShequServiceImpl();
			ShequForm shequForm = new ShequForm();
			
			//如果是新建社区，则登记社区信息表
			if(theForm.getVillageID() == 0 && !theForm.getVillage().equals("")){
	
				//判断社区是否已经创建
				shequForm.setVillage(theForm.getVillage());
				
				List shequlist = shequservice.listByVillage(theForm.getVillage());
				if(shequlist.size() > 0){
					BaseShequ shequbase = (BaseShequ)list.get(0);
		
					theForm.setVillageID(shequbase.getVillageID());
				}else{
					shequForm.setWork_location(theForm.getWork_location());
					shequForm.setWork_sublocation(theForm.getWork_sublocation());
					shequForm.setWork_area(theForm.getWork_area());
					shequForm.setVillage(theForm.getVillage());
					shequForm.setMapXY(theForm.getMapXY());
					shequForm.setMemberNum(1);
					shequForm.setUserID(theForm.getUserID());
					
					shequservice.add(cn, shequForm, msg);
					if(msg.getErrCode()!= 0){
						return ;
					}
					theForm.setVillageID(shequForm.getVillageID());
				}
				
			}else{//不是新建社区，则更新社区人数
				shequForm.Clear();
				shequForm.setMemberNum(1);
				shequForm.setVillageID(theForm.getVillageID());
				
				shequservice.updsts(cn, shequForm, msg);
				if(msg.getErrCode()!= 0){
					return ;
				}
			}
			
			//登记居住信息表
			UserHomeServiceImpl uhomeservice = new UserHomeServiceImpl();
			UserHomeForm uhomeForm = new UserHomeForm();

			BeanUtils.copyProperties(uhomeForm, theForm);
			
			uhomeservice.add(cn, uhomeForm, msg);
			if(msg.getErrCode()!= 0){
				return ;
			}
			//登记会员联系资料表
			ContactsServiceImpl contactservice = new ContactsServiceImpl();
			ContactsForm contactForm = new ContactsForm();
			
			BeanUtils.copyProperties(contactForm, theForm);

			contactservice.add(cn, contactForm, msg);
			if(msg.getErrCode()!= 0){
				return ;
			}

			
			//增加会员100积分
			JifenServiceImpl jifenservice = new JifenServiceImpl();			
			jifenservice.compjf(cn, 1, theForm.getUserID(), msg);
			if(msg.getErrCode() != 0){
				return;
			}
			
			DbcpPool.commitTran(cn);			
			DbcpPool.closeTran(cn);			
			DbcpPool.returnConnection(cn);
			
		} catch(Exception ex) 
		{
			logger.error("System error , param get about invite" + ex);
			common.setAppFailMsg(msg , ex.getMessage());
			try 
			{
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
			} catch(Exception ex1) 
			{
				ex1.printStackTrace();
				logger.error("事务回滚操作失败!ExaServiceImpl->add(01)" , ex1);
			}				
		} finally {
			DbcpPool.returnConnection(cn);
		}		
		
		return;
	}	
	
	/**
	 * 删除一条指定记录
	 * @see net.IUserbasicService.module.other.IUserService#update(net.swift.common.ReturnMessage)
	 */
	public void delete(UsersForm theForm, ReturnMessage msg) 
	{
		
		return ;
	}

	/**
	 * 更新一条指定记录
	 * @see net.IUserbasicService.module.other.IUserService#update(net.swift.common.ReturnMessage)
	 */
	public void update(UsersForm theForm, ReturnMessage msg) 
	{
		Connection cn = null;
		try
		{
			cn = DbcpPool.getConnection();
			
			DbcpPool.beginTran(cn);

			UsersServiceSqlMysql servSql = new UsersServiceSqlMysql();
			BasicSqlService  bSqlServ = new BasicSqlService();
			//取原记录的信息			
			Object[] fields2 = new Object[1];

			fields2[0] = theForm.getUserID();
			
			String sql = servSql.getbykeySql();
		
			List list = bSqlServ.dbRead(cn, sql, fields2, new DbUsersService());
			if(list.size() == 0){
				
				common.setAppFailMsg(msg , " 记录不存在，请检查！");
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
				return;				
			}
			//填充到theForm的空字段中
			BaseUsers base = (BaseUsers)list.get(0);
						
			if(theForm.getNick().equals("")){
				
				theForm.setNick(base.getNick());
			}
			if(theForm.getEmail().equals("")){
				
				theForm.setEmail(base.getEmail());
			}			
			if(theForm.getPassword().equals("")){
				
				theForm.setPassword(base.getPassword());
			}else{
				
				theForm.setPassword(Decode.Encode(theForm.getPassword()));
			}
			if(theForm.getStatus().equals("")){
				
				theForm.setStatus(base.getStatus());
			}
			
			if(theForm.getType().equals("")){
				
				theForm.setType(base.getType());
			}
			if(theForm.getCtime().equals("")){
				
				theForm.setCtime(base.getCtime());
			}
			if(theForm.getLoginCnt() == 0){
				
				theForm.setLoginCnt(base.getLoginCnt());
			}
			if(theForm.getLtime().equals("")){
				
				theForm.setLtime(base.getLtime());
			}
			if(theForm.getOnline().equals("")){
				
				theForm.setOnline(base.getOnline());
			}
			if(theForm.getRemark().equals("")){
				
				theForm.setRemark(base.getRemark());
			}
			
			//取得FORM中传入的查询参数
			Object[] fields = new Object[12];
			
			fields[0] = theForm.getNick();
			fields[1] = theForm.getEmail();
			fields[2] = theForm.getPassword();
			fields[3] = theForm.getStatus();
			fields[4] = theForm.getType();
			fields[5] = theForm.getCtime();
			fields[6] = theForm.getLoginCnt();
			fields[7] = theForm.getLtime();
			fields[8] = theForm.getOnline();
			fields[9] = DatetimeUtil.getDatetime();
			fields[10] = theForm.getRemark();
			fields[11] = theForm.getUserID();
			
			sql = servSql.getUpdateSql();
			
			boolean  res = bSqlServ.dbWrite(cn, sql, fields);
			if(!res){
				common.setAppFailMsg(msg , " 更新记录失败，请检查！");
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
				return;
			}
			//更新详细资料表
			DetailsServiceImpl detailservice = new DetailsServiceImpl();		
			DetailsForm detailForm = new DetailsForm();
			BeanUtils.copyProperties(detailForm, theForm);
			
			//根据身份证取出生日期， 计算生肖 和星座
//			if(theForm.getCertno().length() > 15){
//				String birthday = theForm.getCertno().substring(6, 14);
//				
//				detailForm.setBirthday(birthday);
//				
//	        	int year = Integer.valueOf(birthday.substring(0,4));
//	        	int month = Integer.valueOf(birthday.substring(4,6));
//	        	int day = Integer.valueOf(birthday.substring(6,8));
//	        	
//	        	String nl = ChineseCalendar.sCalendarSolarToLundar( year,  month,  day);
//	        	if(nl.length() >= 8){
//	        		int nlyear = Integer.valueOf(nl.trim().substring(0, 4));
//	        		detailForm.setChzodiac(Ageutil.sxiao(nlyear));				//生肖
//	        	}
//	        	detailForm.setStar(Ageutil.star(month, day));
//			}			
			
			detailservice.update(detailForm, msg);
			if(msg.getErrCode() !=0){
				return;
			}
			
			//更新居住信息表
			UserHomeServiceImpl userhomeservice = new UserHomeServiceImpl();		
			UserHomeForm userhomeForm = new UserHomeForm();
			BeanUtils.copyProperties(userhomeForm, theForm);
			
			userhomeservice.update(userhomeForm, msg);
			if(msg.getErrCode() != 0){
				return;
			}
	
			//更新联系资料表
			ContactsServiceImpl contactservice = new ContactsServiceImpl();
			ContactsForm contactForm = new ContactsForm();
			BeanUtils.copyProperties(contactForm, theForm);
			
			contactservice.update(contactForm, msg);
			if(msg.getErrCode() != 0){
				return;
			}
			
			DbcpPool.commitTran(cn);
			DbcpPool.closeTran(cn);			
			DbcpPool.returnConnection(cn);
			
		} catch(Exception ex) 
		{
			logger.error("System error , param Update about userdetails" + ex);
			common.setAppFailMsg(msg , ex.getMessage());
			try 
			{
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
			} catch(Exception ex1) 
			{
				ex1.printStackTrace();
				logger.error("事务回滚操作失败!ExaServiceImpl->add(01)" , ex1);
			}				
		} finally {
			DbcpPool.returnConnection(cn);
		}
				
		return ;
	}
	
	/**
	 * 更新一条指定记录
	 * @see net.IUserbasicService.module.other.IUserService#update(net.swift.common.ReturnMessage)
	 */
	public void updateuser(UsersForm theForm, ReturnMessage msg) 
	{
		Connection cn = null;
		try
		{
			cn = DbcpPool.getConnection();
			
			DbcpPool.beginTran(cn);

			updateuser(cn, theForm, msg);
			if(msg.getErrCode() != 0){
				return;
			}

			DbcpPool.commitTran(cn);
			DbcpPool.closeTran(cn);			
			DbcpPool.returnConnection(cn);
			
		} catch(Exception ex) 
		{
			logger.error("System error , param Update about userdetails" + ex);
			common.setAppFailMsg(msg , ex.getMessage());
			try 
			{
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
			} catch(Exception ex1) 
			{
				ex1.printStackTrace();
				logger.error("事务回滚操作失败!ExaServiceImpl->add(01)" , ex1);
			}				
		} finally {
			DbcpPool.returnConnection(cn);
		}
				
		return ;
	}
	/**
	 * 更新一条指定记录
	 * @see net.IUserbasicService.module.other.IUserService#update(net.swift.common.ReturnMessage)
	 */
	public void updateuser(Connection cn, UsersForm theForm, ReturnMessage msg) 
	{
		try
		{

			UsersServiceSqlMysql servSql = new UsersServiceSqlMysql();
			BasicSqlService  bSqlServ = new BasicSqlService();
			//取原记录的信息			
			Object[] fields2 = new Object[1];

			fields2[0] = theForm.getUserID();
			
			String sql = servSql.getbykeySql();
		
			List list = bSqlServ.dbRead(cn, sql, fields2, new DbUsersService());
			if(list.size() == 0){
				
				common.setAppFailMsg(msg , " 会员记录不存在，请检查！");
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
				return;				
			}
			//填充到theForm的空字段中
			BaseUsers base = (BaseUsers)list.get(0);
						
			if(theForm.getNick().equals("")){
				
				theForm.setNick(base.getNick());
			}
			if(theForm.getEmail().equals("")){
				
				theForm.setEmail(base.getEmail());
			}			
			if(theForm.getPassword().equals("")){
				
				theForm.setPassword(base.getPassword());
			}else{
				
				theForm.setPassword(Decode.Encode(theForm.getPassword()));
			}
			if(theForm.getStatus().equals("")){
				
				theForm.setStatus(base.getStatus());
			}
			
			if(theForm.getType().equals("")){
				
				theForm.setType(base.getType());
			}
			if(theForm.getCtime().equals("")){
				
				theForm.setCtime(base.getCtime());
			}
			if(theForm.getLoginCnt() == 0){
				
				theForm.setLoginCnt(base.getLoginCnt());
			}
			if(theForm.getLtime().equals("")){
				
				theForm.setLtime(base.getLtime());
			}
			if(theForm.getOnline().equals("")){
				
				theForm.setOnline(base.getOnline());
			}
			if(theForm.getRemark().equals("")){
				
				theForm.setRemark(base.getRemark());
			}
			
			//取得FORM中传入的查询参数
			Object[] fields = new Object[12];
			
			fields[0] = theForm.getNick();
			fields[1] = theForm.getEmail();
			fields[2] = theForm.getPassword();
			fields[3] = theForm.getStatus();
			fields[4] = theForm.getType();
			fields[5] = theForm.getCtime();
			fields[6] = theForm.getLoginCnt();
			fields[7] = theForm.getLtime();
			fields[8] = theForm.getOnline();
			fields[9] = DatetimeUtil.getDatetime();
			fields[10] = theForm.getRemark();
			fields[11] = theForm.getUserID();
			
			sql = servSql.getUpdateSql();
			
			boolean  res = bSqlServ.dbWrite(cn, sql, fields);
			if(!res){
				common.setAppFailMsg(msg , " 更新记录失败，请检查！");
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
				return;
			}

		} catch(Exception ex) 
		{
			logger.error("System error , param Update about userdetails" + ex);
			common.setAppFailMsg(msg , ex.getMessage());
			try 
			{
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
			} catch(Exception ex1) 
			{
				ex1.printStackTrace();
				logger.error("事务回滚操作失败!ExaServiceImpl->add(01)" , ex1);
			}				
		} finally {
		}
				
		return ;
	}	
	
	/**
	 * 
	 * @see net.IUserbasicService.module.other.IUserService
	 * 		#list(net.swift.module.other.ExaQueryBean, net.swift.common.ReturnMessage)
	 */
	public String[] getinterest(UsersForm theForm,  ReturnMessage msg) 
	{
		//List list = new Vector();
		String Interest = "";
		String InterestSet = "";
		Connection cn = null;
		Statement stmt=null;
		ResultSet rs=null;
		try
		{
			cn = DbcpPool.getConnection();
			
			UsersServiceSqlMysql servSql = new UsersServiceSqlMysql();

			
			 //取记录
			 //sql = servSql.getinterestByUserIDSql();
			//String interestsql = servSql.getinterestByUserIDSql();
			// logger.debug(interestsql);
			// DbUsersService dbuser = new DbUsersService();
			 
			 rs=cn.createStatement().executeQuery("select Interest,InterestSet from Userdetails where UserID="+theForm.getUserID());
			
			 while (rs.next())
			 {
				 Interest = rs.getString("Interest");
				 InterestSet = rs.getString("InterestSet");
			 }
			 rs.close();
			 stmt.close();
		     DbcpPool.returnConnection(cn);

		} catch(Exception ex) 
		{
			/**
			 * 记录相关日志
			 */
			logger.error(ex.getMessage());
			try {
				if (rs != null)
					rs.close();
				if (stmt != null)
					stmt.close();
				DbcpPool.returnConnection(cn);
			} catch (Exception ex1) {
				ex1.printStackTrace();
			}			
	    }finally {
			try {
				if (rs != null)
					rs.close();
				if (stmt != null)
					stmt.close();
			} catch (Exception ex) {
				ex.printStackTrace();
			}			
			DbcpPool.returnConnection(cn);
		}		   
		return new String[]{Interest,InterestSet};
	}	
	
	public void saveInterest(UsersForm theForm) 
	{
		//List list = new Vector();
		String Interest = theForm.getInterest();
		String interestSet = theForm.getInterestSet();
		Connection cn = null;
		try
		{
			cn = DbcpPool.getConnection();

			 
			 cn.createStatement().execute("update Userdetails set InterestSet='" + interestSet + "',Interest = '" + Interest + "'  where UserID="+theForm.getUserID());

		     DbcpPool.returnConnection(cn);

		} catch(Exception ex) 
		{
			/**
			 * 记录相关日志
			 */
			logger.error(ex.getMessage());
			try {
				DbcpPool.returnConnection(cn);
			} catch (Exception ex1) {
				ex1.printStackTrace();
			}			
	    }finally {
			try {
			} catch (Exception ex) {
				ex.printStackTrace();
			}			
			DbcpPool.returnConnection(cn);
		}		   
	}	

}
